<template>
	<view class="content">
		<view class="section-0">
			<view class="section-body">
				<timeLine :list="list"></timeLine>
			</view>
		</view>
	</view>
</template>

<script>
	const riskMap = {
		work_type: {
			name: '项目名称',
			filter: (val) => val
		},
		risk_level: {
			name: '风险等级',
			filter: (val) => val
		},
		work_position: {
			name: '作业部位',
			filter: (val) => val
		},
		work_name: {
			name: '作业票名称',
			filter: (val) => val
		},
		address: {
			name: '地址位置',
			filter: (val) => val
		},
		start_time: {
			name: '计划开始时间',
			filter: (val) => val ? val.substring(0, 10) : '-'
		},
		end_time: {
			name: '计划完成时间',
			filter: (val) => val ? val.substring(0, 10) : '-'
		},
		start_time_real: {
			name: '实际开始时间',
			filter: (val) => val ? val.substring(0, 10) : '-'
		},
		end_time_real: {
			name: '实际完成时间',
			filter: (val) => val ? val.substring(0, 10) : '-'
		},
		gk_measure: {
			name: '管控措施',
			filter: (val) => val
		},
		lc_status: {
			name: '流程状态',
			filter: (val) => val
		},
		oper_time: {
			name: '导入时间',
			filter: (val) => val ? val.substring(0, 10) : '-'
		},
	}
	import {
		projectRiskInfoApi
	} from '@/api/statistics.js';
	import {
		addRiskApi,
		updateRiskApi
	} from '@/api/risk.js'
	import timeLine from '../../../components/time_line/index.vue'
	export default {
		components: {
			timeLine
		},
		data() {
			return {
				name: '',
				id: '',
				list: [],
				info: []
			};
		},
		methods: {

			handleShowPop(type) {
				this.clearForm();
				if (type == 'update') {
					this.form = JSON.parse(JSON.stringify(this.info));
				}
				this.type = type;
				this.showPop = true;
			},
			closePop() {
				this.showPop = false;
			},

			go(item) {
				uni.navigateTo({
					url: '/pages/statistics/today/risk/info/detail/index'
				})
			},
			async fetchData() {
				uni.showLoading({
					title: '加载中...'
				});

				const {
					data
				} = await projectRiskInfoApi({
					id: 8410
				});
				uni.hideLoading();
				if (data.code === 1) {
					let arr = [];
					let res = data.data[0];
					for (let key in res) {
						let item = {};
						if (riskMap[key]) {
							item = {
								title: riskMap[key].name,
								content: {
									type: 'text',
									value: riskMap[key].filter(res[key])
								}
							}
							arr.push(item);
						}
					}
					this.info = res;
					this.list = arr;
				}
			}
		},
		onLoad(data) {
			this.id = JSON.parse(data.params).id
			this.name = JSON.parse(data.params).project_name;
			this.curd = JSON.parse(data.params).curd;
		},
		onReady() {
			this.fetchData();
		}
	}
</script>

<style lang="scss" scoped>
	.section-0 {
		width: 100%;
		background-color: #3a5df5;

		.section-body {
			padding-top: 50rpx;
			box-sizing: border-box;
			width: 100%;
			padding-left: 40rpx;
			padding-right: 40rpx;
			padding-bottom: 100rpx;
			background-color: #fff;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
		}
	}
</style>
